package Object_study;

public class Person {
    private  String name;
    private int age;

    //重写toString
    @Override
    public String toString() {
        //原来的返回值return super.toString();
        return "name="+name+",age = "+age+"";
    }
    //重写equals
    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Person) {
            //先向下转型，将obj转为Person
            Person p = (Person) obj;
            return (this.name.equals(p.name) && this.age == p.age);
            //前面的是比较name的字符串，后面是比较age的值
            //return super.equals(obj);
        }
        else {
            return false;
        }
    }

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}


